#include <EndGameState.h>

template<> EndGameState* Ogre::Singleton<EndGameState>::ms_Singleton = 0;

void EndGameState::enter()
{
  _overlayMgr = Ogre::OverlayManager::getSingletonPtr();
  _overlayMgr->getByName("EndGameImage")->show();
  _overlayMgr->getOverlayElement("Pause")->hide();

  if (_endType == Win)
  {
    _overlayMgr->getOverlayElement("winImage")->show();
    _overlayMgr->getOverlayElement("failImage")->hide();
  }

  else
  {
    _overlayMgr->getOverlayElement("winImage")->hide();
    _overlayMgr->getOverlayElement("failImage")->show();
  }

  _exitGame = false;
  _endType = Fail;
}

void EndGameState::exit()
{
  _overlayMgr->getByName("EndGameImage")->hide();
}

void EndGameState::pause() {}

void EndGameState::resume() {}

bool EndGameState::frameStarted(const Ogre::FrameEvent& evt)
{
  return true;
}

bool EndGameState::frameEnded(const Ogre::FrameEvent& evt)
{
  return not _exitGame;
}

void EndGameState::keyPressed(const OIS::KeyEvent& e)
{
  popState();
}

void EndGameState::keyReleased(const OIS::KeyEvent& e) {}

void EndGameState::mouseMoved(const OIS::MouseEvent& e) {}

void EndGameState::mousePressed(const OIS::MouseEvent& e, OIS::MouseButtonID id) {}

void EndGameState::mouseReleased(const OIS::MouseEvent& e, OIS::MouseButtonID id) {}

void EndGameState::setType(const EndType e)
{
  _endType = e;
}

EndGameState* EndGameState::getSingletonPtr()
{
  return ms_Singleton;
}

EndGameState& EndGameState::getSingleton()
{ 
  assert(ms_Singleton);
  return *ms_Singleton;
}
